package com.tzbank.back.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tzbank.back.service.IntegralDeployService;
import com.tzbank.entity.backstage.IntegralDeploy;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * 积分管理配置
 * @author 蔡宇钿
 *2018年6月4日
 */

@Slf4j
@RestController
public class IntegralDeployController {

	@Autowired
	private IntegralDeployService integralDeployService;
	
	@PostMapping(value = "getlistIntegral")
	public Map<String, Object> getlistByintegralactivname(HttpServletRequest request,  @RequestParam(required = false) String activename) {
		try {
			if (null == activename ) {
				return this.integralDeployService.getlistIntegral();
			}else {
				return this.integralDeployService.getlistByintegralactivname(activename);
			}
			
		} catch (Exception e) {
			log.error("IntegralDeployController selectByintactiv: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	@PostMapping(value = "addIntegral")
	// 增加配置
	public Map<String, Object> addIntegral(HttpServletRequest request,@RequestBody IntegralDeploy integralDeploy) {
		try {
			return this.integralDeployService.addIntegral(integralDeploy);
		} catch (Exception e) {
			log.error("IntegralDeployController insertByint: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	@PostMapping(value = "modifyByintegralautoId")
	// 更新配置
	public Map<String, Object> modifyByintegralautoId(HttpServletRequest request, @RequestBody IntegralDeploy integralDeploy) {
		try {
			return this.integralDeployService.modifyByintegralautoId(integralDeploy);
		} catch (Exception e) {
			log.error("IntegralDeployController updateByintauto n: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	@PostMapping(value = "deleteByintegralautoId")
	// 通过逻辑方式实现删除
	public Map<String, Object> deleteByintegralautoId(HttpServletRequest request, @RequestBody IntegralDeploy integralDeploy) {
		try {
			return this.integralDeployService.deleteByintegralautoId(integralDeploy);
		} catch (Exception e) {
			log.error("IntegralDeployController deleteByintauto: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}
}
